
<template>
  <router-view />
</template>
<script setup>
  import {onBeforeMount} from 'vue';
  import {cosSystem} from '@/stores/system.js';
  import {useRouter} from 'vue-router';
  const router = useRouter();
  let store = cosSystem();

  onBeforeMount(() => {
    //刷新  清除标志 重新加载路由
    store.flag = 0;
    loadRouter();
  });
  const menuDs = [];
  const loadRouter = () => {
    //菜单重置 路由重置
    store.restMenu();
    const modules = import.meta.glob("./views/**/*.vue")
    const menu  = store.getMeun;
    menu.forEach(element => {
      initRouter(element)
    });
    menuDs.forEach(item=>{
       if (item.menuCode!=""&&!router.hasRoute(item.menuCode)) {
            router.addRoute(item.spaceZone, {
              path: item.routerPath,
              meta: {title: item.menuName},
              name: item.menuCode,
              component:modules[ './views/'+ `${item.filePath}`+'.vue']
          });
        }
    
    })

  };  

  const initRouter = (route=>{
    if(route.children){
      initRouter(route.children)
    }else{
      if(Array.isArray(route)){
          route.forEach(item=>{
            initRouter(item);
        })
      }else{
        menuDs.push(route);
      } 
    }
  })
</script>
<style scoped>
html, body {
  margin: 0px !important;
  padding: 0px !important;
  
}
</style>
